package com.work.service.impl;

import com.work.bean.Message;
import com.work.bean.Student;
import com.work.dao.MessageDao;
import com.work.dao.StudentDao;
import com.work.dao.impl.MessageDaoImpl;
import com.work.dao.impl.StudentDaoImpl;
import com.work.dto.Mstudent;
import com.work.service.MessageService;

import java.util.ArrayList;
import java.util.List;

public class MessageServiceImpl implements MessageService {
    MessageDao messageDao = new MessageDaoImpl();
    StudentDao studentDao = new StudentDaoImpl();
    @Override
    public List<Message> queryMessage() {
        return messageDao.queryMessage();
    }

    @Override
    public int saveMessage(Message message) { return messageDao.saveMessage(message);
    }

    @Override
    public int deleteMessage(Integer id) {
        return messageDao.deleteMessage(id);
    }

    @Override
    public List<Message> queryMessageBytId(Integer t_id) {
        return messageDao.queryMessageBytId(t_id);
    }

    @Override
    public Message queryMessageBysId(Integer s_id) {
        return messageDao.queryMessageBysId(s_id);
    }

    @Override
    public List<Mstudent> queryMessage1(Integer t_id) {
        List<Mstudent> list = new ArrayList<Mstudent>();
        List<Message> messages = messageDao.queryMessageBytId(t_id);
        for (Message value: messages) {
            String sname = studentDao.queryStudentById(value.getS_id()).getSname();
            String status = "";
            if(value.getState() == 0){
                 status = "未读";
            }else if(value.getState() == 1){
                 status = "已读";
            }
            Mstudent mstudent = new Mstudent(value.getId(),value.getTitle(),value.getContent(),sname,value.getT_id(),value.getTime(),status);
            list.add(mstudent);
        }
        return list;
    }
}
